package jmine.tec.rpc.server.representation.representers.collections;

import java.util.HashMap;
import java.util.Map;

import jmine.tec.rpc.server.representation.RepresentationContext;
import jmine.tec.rpc.server.representation.representers.AbstractRepresenter;

/**
 * Representador de mapas.
 * 
 * @author lundberg
 */
public class MapRepresenter extends AbstractRepresenter<Map, MapRepresenterBean> {

    /**
     * Construtor
     */
    public MapRepresenter() {
        super(Map.class, MapRepresenterBean.class);
    }

    /**
     * {@inheritDoc}
     */
    public Map represent(RepresentationContext context, MapRepresenterBean object) {
        Map<Object, Object> representation = new HashMap<Object, Object>(object.getObjects().size());
        context.register(object, representation);
        for (Map.Entry<?, ?> represented : object.getObjects().entrySet()) {
            Object key = context.representObject(object.getKeyClass(), represented.getKey());
            Object value = context.representObject(object.getValueClass(), represented.getValue());
            representation.put(key, value);
        }
        return representation;
    }
}
